package my.sample.channel.datagram;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.nio.channels.DatagramChannel;

public class IcmpFromFile {

	public static void main(String[] args) {
		
/*		
		if(args.length < 1)
		
		
//		byte[] data = new byte[1024];
		int readBytes;
		try {
		  FileInputStream in = new FileInputStream(new File("/tmp/icmpdata.cap"));
		  while ((readBytes = in.read(data)) != -1) {
		    System.out.println("read " + readBytes + " bytes, and placed them into temp array named data");
		  }
		  in.close();
		} catch (Exception e) {
		  e.printStackTrace();
		}
		
		InetSocketAddress ipAddress = null;
		DatagramChannel channel = null;
		
		
		try {
			ipAddress = new InetSocketAddress(InetAddress.getByName(args[0]), Integer.parseInt(args[1]));
		} catch (NumberFormatException e1) {
			e1.printStackTrace();
		} catch (UnknownHostException e1) {
			e1.printStackTrace();
		}
		
		
		InetAddress ip = InetAddress.getByName("www.google.com");
		ip.isReachable(1000);
		
		try {
			channel = DatagramChannel.open();
			channel.connect(ipAddress);
			channel.socket().setSendBufferSize(131071);
//			System.out.println("connection status : " + channel.isConnected());
//			System.out.println("open status : " + channel.isOpen());
		} catch (IOException e) {
			try {
				channel.close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		} catch (Exception e1) {
			e1.printStackTrace();
		}
	}
*/
	}

}